package net.framework.smc.demo.po;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @authore zyx
 * @date 2018/6/27 11:12
 */
public class ResultPo extends HashMap<String, Object> {

    public ResultPo(){
        put("msg", "操作成功");
        put("code", 1);
    }

    public static ResultPo error(){
        return error(500, "发生未知错误!");
    }

    public static ResultPo error(String msg){
        return error(500, msg);
    }

    public static ResultPo error(int code, String msg){
        ResultPo resultPo = new ResultPo();
        resultPo.put("code", code);
        resultPo.put("msg", msg);
        return  resultPo;
    }

    public static ResultPo success(){
        return new ResultPo();
    }

    public static ResultPo success(String msg){
        ResultPo resultPo = new ResultPo();
        resultPo.put("msg", msg);
        return resultPo;
    }

    public static ResultPo success(Map map){
        ResultPo resultPo = new ResultPo();
        resultPo.put("data", map);
        return resultPo;
    }

    public static ResultPo success(Object object) {
        ResultPo resultPo = new ResultPo();
        resultPo.put("data", object);
        return resultPo;
    }

    public static ResultPo success(List list){
        ResultPo resultPo = new ResultPo();
        resultPo.put("data", list);
        return resultPo;
    }
}
